package org.locker.device.controller.admin;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.locker.common.idempotent.annotation.RepeatSubmit;
import org.locker.common.log.annotation.Log;
import org.locker.common.web.core.BaseController;
import org.locker.common.mybatis.core.page.PageQuery;
import org.locker.common.core.domain.R;
import org.locker.common.core.validate.AddGroup;
import org.locker.common.core.validate.EditGroup;
import org.locker.common.log.enums.BusinessType;
import org.locker.common.excel.utils.ExcelUtil;
import org.locker.domain.vo.BluetoothVersionVo;
import org.locker.domain.bo.BluetoothVersionBo;
import org.locker.service.IBluetoothVersionService;
import org.locker.common.mybatis.core.page.TableDataInfo;

/**
 * 蓝牙升级信息
 *
 * @author winnie
 * @date 2023-10-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/device/bluetoothVersion")
public class BluetoothVersionController extends BaseController {

    private final IBluetoothVersionService bluetoothVersionService;

    /**
     * 查询蓝牙升级信息列表
     */
    @SaCheckPermission("device:bluetoothVersion:list")
    @GetMapping("/list")
    public TableDataInfo<BluetoothVersionVo> list(BluetoothVersionBo bo, PageQuery pageQuery) {
        return bluetoothVersionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出蓝牙升级信息列表
     */
    @SaCheckPermission("device:bluetoothVersion:export")
    @Log(title = "蓝牙升级信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BluetoothVersionBo bo, HttpServletResponse response) {
        List<BluetoothVersionVo> list = bluetoothVersionService.queryList(bo);
        ExcelUtil.exportExcel(list, "蓝牙升级信息", BluetoothVersionVo.class, response);
    }

    /**
     * 获取蓝牙升级信息详细信息
     *
     * @param bluetoothVersionId 主键
     */
    @SaCheckPermission("device:bluetoothVersion:query")
    @GetMapping("/{bluetoothVersionId}")
    public R<BluetoothVersionVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long bluetoothVersionId) {
        return R.ok(bluetoothVersionService.queryById(bluetoothVersionId));
    }

    /**
     * 新增蓝牙升级信息
     */
    @SaCheckPermission("device:bluetoothVersion:add")
    @Log(title = "蓝牙升级信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BluetoothVersionBo bo) {
        return toAjax(bluetoothVersionService.insertByBo(bo));
    }

    /**
     * 修改蓝牙升级信息
     */
    @SaCheckPermission("device:bluetoothVersion:edit")
    @Log(title = "蓝牙升级信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BluetoothVersionBo bo) {
        return toAjax(bluetoothVersionService.updateByBo(bo));
    }

    /**
     * 删除蓝牙升级信息
     *
     * @param bluetoothVersionIds 主键串
     */
    @SaCheckPermission("device:bluetoothVersion:remove")
    @Log(title = "蓝牙升级信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bluetoothVersionIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] bluetoothVersionIds) {
        return toAjax(bluetoothVersionService.deleteWithValidByIds(List.of(bluetoothVersionIds), true));
    }
}
